import 'package:love_app/common/su_dio.dart';
import 'package:love_app/config/path_url.dart';
import 'package:love_app/model/community_model.dart';
import 'package:love_app/model/response_model.dart';
import 'package:love_app/service/base_api.dart';

// 社区页面获取数据api
class CommunityApi extends BaseApi{

  // 获取数据（暂时社区页面的推荐，最新，关注页面三个model是一样的）
  Future<CommunityModel> getCommunityData(String token, String path)async{
    Map header = {
      'X-Auth-Token': token,
    };
    ResponseModel responseModel = await SuDio().getRequest(path, headersMap: header);
    return CommunityModel.fromJson(responseModel.toJsonModel);
  }

  // 获取社区搜索结果
  Future<CommunityModel> getCommunitySearch(String token, String searchData, {int page = 1, int limit = 5}) async {
    String path = PathUrl.search;
    Map data = {
      "search_content": searchData,
      "page": page,
      "limit": limit,
    };
    ResponseModel model = await SuDio().getRequest(path, headersMap: headerToken(token), queryParams: data);
    return CommunityModel.fromJson(model.toJsonModel);
  }
}